// EcoModeler - C# Edition :: Version 9.17 build 3378
using System;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using Eco.Services;
using Eco.ObjectRepresentation;
using Eco.ObjectImplementation;
using Eco.UmlRt;
using Eco.UmlCodeAttributes;
using Eco.Subscription;
using EcoExtensions.Model;

using Axiom;
using Axiom.Core;
using Axiom.Math;

namespace VisualDM.Model
{
	#region MM_ECO_Generated
	#region Attributes
	[UmlElement(Id="{a2d81793-e856-49a3-947f-407e7b5a95e7}")]
	#endregion

	#endregion
	public class CameraSceneObject: SceneObject
	{
		#region MM_ECO AutoGenerated ECO code

		new public struct Eco_LoopbackIndices
		{
			public const int Eco_FirstMember = VisualDM.Model.SceneObject.Eco_LoopbackIndices.Eco_MemberCount;
			public const int Eco_MemberCount = (Eco_FirstMember + 3);
			public const int DefaultDirection_MemberIndex = Eco_FirstMember + 0;
			public const int DefaultLookAt_MemberIndex = Eco_FirstMember + 1;
			public const int DependencyObjectID_MemberIndex = Eco_FirstMember + 2;
		}
		#endregion

		#region MM_ECO Model owned attributes
		//Note: Do not remove any property within this region, nor change its signature

		#region MM_ECO_Generated
		[UmlElement("AssociationEnd", Index=(CameraSceneObject.Eco_LoopbackIndices.DefaultDirection_MemberIndex), Id="{39807051-9c3b-45c9-aef2-bb71dd679b91}")]
		[UmlMetaAttribute("association", typeof(VisualDMPackage.CameraSceneObjectEcoVector), Index=1)]
		[UmlMetaAttribute("multiplicity", "1")]
		#endregion
		public EcoVector DefaultDirection
		{
			get
			{
				#region MM_ECO_Generated
				return (EcoVector) (this.eco_Content.get_MemberByIndex(Eco_LoopbackIndices.DefaultDirection_MemberIndex));
				#endregion
			}
			set
			{
				#region MM_ECO_Generated
				this.eco_Content.set_MemberByIndex(Eco_LoopbackIndices.DefaultDirection_MemberIndex, ((object)(value)));
				#endregion
			}
		}

		#region MM_ECO_Generated
		[UmlElement("AssociationEnd", Index=(CameraSceneObject.Eco_LoopbackIndices.DefaultLookAt_MemberIndex), Id="{9b7aa161-b5ba-4109-b08d-938be9f69938}")]
		[UmlMetaAttribute("association", typeof(VisualDMPackage.CameraSceneObjectEcoVector1), Index=1)]
		[UmlMetaAttribute("multiplicity", "1")]
		#endregion
		public EcoVector DefaultLookAt
		{
			get
			{
				#region MM_ECO_Generated
				return (EcoVector) (this.eco_Content.get_MemberByIndex(Eco_LoopbackIndices.DefaultLookAt_MemberIndex));
				#endregion
			}
			set
			{
				#region MM_ECO_Generated
				this.eco_Content.set_MemberByIndex(Eco_LoopbackIndices.DefaultLookAt_MemberIndex, ((object)(value)));
				#endregion
			}
		}

		#region MM_ECO_Generated
		#region Attributes
		[UmlElement(Index=(CameraSceneObject.Eco_LoopbackIndices.DependencyObjectID_MemberIndex), Id="{2c03043f-4570-4c4a-aafa-61fb65c98094}")]
		[UmlTaggedValue("Eco.Length", "255")]
		#endregion

		#endregion
		public int DependencyObjectID
		{
			get
			{
				#region MM_ECO_Generated
				return (int) (this.eco_Content.get_MemberByIndex(Eco_LoopbackIndices.DependencyObjectID_MemberIndex));
				#endregion
			}
			set
			{
				#region MM_ECO_Generated
				this.eco_Content.set_MemberByIndex(Eco_LoopbackIndices.DependencyObjectID_MemberIndex, ((object)(value)));
				#endregion
			}
		}
		#endregion

		#region MM_ECO Model owned methods
		//Note: Do not remove any method within this region, nor change its signature

		public CameraSceneObject(IContent content) : base(content)
		{
			#region MM_ECO_Generated
			#endregion
		}

		public CameraSceneObject(IEcoServiceProvider serviceProvider) : base(serviceProvider)
		{
			try
			{
				DefaultDirection = new EcoVector(serviceProvider);
								DefaultLookAt = new EcoVector(serviceProvider);
			}
			catch (System.Exception)
			{
				this.Deinitialize(serviceProvider);
				throw;
			}
		}
		#endregion

        public Camera camera;
        private SceneObject DependencyObject;

        public Vector3 Direction { get { return ((camera!=null)?camera.Direction:DefaultDirection); } set { if (camera!=null) camera.Direction = value; else DefaultDirection.Vector=value; } }
        public Vector3 Position { get { return ((camera!=null)?camera.Position:DefaultPosition); } set { if (camera!=null) camera.Position = value; else DefaultPosition.Vector = value; } }
        public Vector3 lookAt;

        public override void Initialize(SceneNode node, SceneManager sm, bool reset)
        {
            base.Initialize(node,sm,false);
            if (camera==null)
            {
                camera = sm.CreateCamera(Name);                
            }
            Position = new Vector3(DefaultPosition.Vector.x, DefaultPosition.Vector.y, DefaultPosition.Vector.z);
            lookAt = DefaultLookAt.Vector;
            camera.LookAt(lookAt);
            camera.Near = 0.1f;
            camera.Far = 100000;
//            camera.CastShadows = true;
            camera.AutoAspectRatio = true;
        }

        public override void ResetToInitPositions()
        {
//                    Initialize(SceneNode,SceneManager);
//                CheckPoints.Push(new CheckPoint(camera.Position, camera.Orientation, new Vector3()));
        }

        public override void RollBack()
        {
        }

        public override void SetCheckPoint()
        {
        }

        public void SetDependencyObject(SceneObject o)
        {
            DependencyObject = o;
        }

                public override void Translate(Vector3 v)
        {
            if ((SceneNode != null) && (camera != null))
            {
                camera.Move(v);
            }
        }
        public override void Yaw(float v)
        {
            if ((SceneNode != null) && (camera != null))
            {
                camera.Yaw(v);
            }
        }
        public override void Pitch(float v)
        {
            if ((SceneNode != null) && (camera != null))
            {
                camera.Pitch(v);
            }
        }

        public void MoveRelative(Vector3 v)
        {
            if (camera != null)
                camera.MoveRelative(v);
        }

        public float GetFOV()
        {
            return camera.FieldOfView;
        }

        public void SetFOV(float f)
        {
            camera.FieldOfView = f;
        }

        public override void LookAt(Vector3 target)
        {
            if (camera != null)
            {
                camera.LookAt(target);
            }
        }

        public void SetAspectRatio(float a)
        {
            camera.AspectRatio = a;
        }
	}
}
